package com.example.jd.common;

import lombok.Data;

/**
 * @author: fudaolai
 * @createDate: 2019/9/9
 * @company: (C) Copyright fotron
 * @since: JDK 1.8
 * @Description:
 */
@Data
@SuppressWarnings("all")
public class InvokeResultUtil<T> {

    private int code = 200;
    private String message;
    private T data;

    public InvokeResultUtil() {
    }

    private InvokeResultUtil(int code, String message) {
        this.code = code;
        this.message = message;
    }

    private InvokeResultUtil(T data) {
        this.data = data;
    }

    public int getCode() {
        return this.code;
    }

    public boolean isSuccess() {
        return this.code == 200;
    }

    public String getMessage() {
        return this.message;
    }

    public T getData() {
        return this.data;
    }

    public void setCode(int code) {
        this.code = code;
    }

    public void setData(T data) {
        this.data = data;
    }

    public void setMessage(String message) {
        this.message = message;
    }

    public static <T> InvokeResultUtil<T> success(T data) {
        InvokeResultUtil<T> result = new InvokeResultUtil(data);
        result.setCode(200);
        result.setMessage("success");
        return result;
    }
    public static <T> InvokeResultUtil<T> error(T data) {
        InvokeResultUtil<T> result = new InvokeResultUtil(data);
        result.setCode(500);
        result.setMessage("error");
        return result;
    }
    public static <T> InvokeResultUtil<T> failure(int code, String message) {
        return new InvokeResultUtil(code, message);
    }
}
